﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 物料类型
    /// </summary>
    public partial class MaterielType : BusEntity
    {
        /// <summary>
        /// 类型编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 类型名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 类型说明
        /// </summary>
        public string Desc { set; get; }
    }

    public partial class MaterielType : BusEntity
    {
        /// <summary>
        /// 物料类型下所有的物料
        /// </summary>
        public List<MaterielInfor> Materiels { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class MaterielTypeTypeConfig : BusEntityTypeConfig<MaterielType>, IEntityTypeConfiguration<MaterielType>
    {
        public override void Configure(EntityTypeBuilder<MaterielType> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefMiddleColLen);
            #endregion

            #region 备注
            builder.HasComment("物料类型/物料分类");
            builder.Property(p => p.Code).HasComment("类型编码");
            builder.Property(p => p.Name).HasComment("类型名称");
            builder.Property(p => p.Desc).HasComment("类型备注说明");
            #endregion

            #region 种子数据
            builder.HasData(new MaterielType() { Id = "CP", Code = "CP", Name = "产品", Desc = "本生产线下线的成品", CreateUserId = "1", ModifyUserId = "1", Deleted = false, CreateTime = DateTime.Now, ModifyTime = DateTime.Now });
            builder.HasData(new MaterielType() { Id = "YCL", Code = "YCL", Name = "原材料", Desc = "线外原材料", CreateUserId = "1", ModifyUserId = "1", Deleted = false, CreateTime = DateTime.Now.AddMinutes(1), ModifyTime = DateTime.Now.AddMinutes(1) });
            //builder.HasData(new MaterielType() { Id = "FL", Code = "FL", Name = "生产辅料", Desc="生产所需的辅料", CreateUserId = "1", ModifyUserId = "1", Deleted = false, CreateTime = DateTime.Now.AddMinutes(2), ModifyTime = DateTime.Now.AddMinutes(2) });
            builder.HasData(new MaterielType() { Id = "XLZJ", Code = "XLZJ", Name = "线内组件", Desc="生产工位下线的产品组成部件（半成品）", CreateUserId = "1", ModifyUserId = "1", Deleted = false, CreateTime = DateTime.Now.AddMinutes(3), ModifyTime = DateTime.Now.AddMinutes(3) });
            //builder.HasData(new MaterielType() { Id = "GZ", Code = "GZ", Name = "工装", Desc = "生产过程中随加工件流转的工具", CreateUserId = "1", ModifyUserId = "1", Deleted = false, CreateTime = DateTime.Now.AddMinutes(4), ModifyTime = DateTime.Now.AddMinutes(4) });
            //builder.HasData(new MaterielType() { Id = "QT", Code = "QT", Name = "其他", Desc = "其他类型材料", CreateUserId = "1", ModifyUserId = "1", Deleted = false, CreateTime = DateTime.Now.AddMinutes(5), ModifyTime = DateTime.Now.AddMinutes(5) });
            #endregion
        }
    }
}
